package ai.people.netmon.framework.domain.archives.vo;

import ai.people.netmon.framework.constant.NumberHideConstant;
import ai.people.netmon.framework.domain.archives.entity.ArchivesBaseInfo;
import ai.people.netmon.framework.domain.archives.entity.ArchivesCompanyInfo;
import ai.people.netmon.framework.domain.archives.entity.ArchivesSocialInfo;
import ai.people.netmon.utils.NumberUtils;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.serializer.ToStringSerializer;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.List;

import static java.util.stream.Collectors.toList;

/**
 * 档案返回VO
 *
 * @author zhenglin
 * @since 2022/3/30
 */
@Data
@NoArgsConstructor
public class ArchivesDetailVO {

    /**
     * 主键ID
     */
    @NotNull(message = "id 不能为空")
    @JSONField(serializeUsing = ToStringSerializer.class)
    private Long id;

    /**
     * 姓名
     */
    private List<String> names;

    /**
     * 性别 0:未知, 1:男 ,2:女
     *
     * @mock 1
     */

    private Integer gender;

    /**
     * 照片
     */
    private String picture;

    /**
     * 出生日期
     */
    @JSONField(format = "yyyy-MM-dd")
    private String birthday;

    /**
     * 体重
     */
    private Double weight;

    /**
     * 身高
     */
    private Double height;

    /**
     * 籍贯
     */
    private String hometown;

    /**
     * 现居地
     */
    private String residentialAddress;

    /**
     * 爱好
     */
    private String hobby;

    /**
     * 身份证
     *
     * @mock 500000000000000000
     */
    private String idNumber;

    /**
     * 护照
     */
    private String passport;

    /**
     * 手机号
     */
    private List<String> phoneNumbers;

    /**
     * 车牌号
     */
    private List<String> plateNumbers;

    /**
     * 标签
     */
    private List<String> tags;

    /**
     * 银行账号
     */
    private List<ArchivesVO.Bank> bankAccounts;

    /**
     * 教育经历
     */
    private List<ArchivesVO.Education> educationExperiences;

    /**
     * 就业经历
     */
    private List<ArchivesVO.Work> workExperiences;

    /**
     * 政治立场
     */
    private String political;

    /**
     * 家庭信息
     */
    private String familySituation;

    /**
     * 个人信息
     */
    private String personalSituation;

    /**
     * 档案研判
     */
    private String archivesJudgment;

    /**
     * 备注
     */
    private String note;

    /**
     * 创建人
     */
    private String creator;

    /**
     * 创建时间
     */
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;

    /**
     * 公司信息列表
     */
    ArchivesVO.CompanyInfo companyInfo;

    /**
     * 社交媒体
     */
    SocialInfo socialInfo;


    public ArchivesDetailVO(ArchivesBaseInfo baseInfo, boolean hide) {
        this.id = baseInfo.getId();
        this.names = baseInfo.buildName();
        this.gender = baseInfo.getGender();
        this.picture = baseInfo.getPicture();
        this.birthday = baseInfo.getBirthday();
        this.weight = baseInfo.getWeight();
        this.height = baseInfo.getHeight();
        this.hometown = baseInfo.getHometown();
        this.residentialAddress = baseInfo.getResidentialAddress();
        this.hobby = baseInfo.getHobby();
        this.tags = baseInfo.buildTags();


        if (hide) {
            this.idNumber = NumberUtils.hideBit(baseInfo.getIdNumber(), NumberHideConstant.ID_HIDE);
            this.phoneNumbers = baseInfo.buildPhone().stream().map(x1 ->NumberUtils.hideBit(x1, NumberHideConstant.PHONE_HIDE)).collect(toList());
            this.plateNumbers = baseInfo.buildPlate().stream().map(x->NumberUtils.hideBit(x, NumberHideConstant.CAR_HIDE)).collect(toList());
            List<ArchivesVO.Bank> banks = baseInfo.buildBankAccount();
            banks.forEach(x -> x.setBankAccount(NumberUtils.hideBit(x.getBankAccount(), NumberHideConstant.BANK_HIDE)));
            this.bankAccounts = banks;
            this.passport = NumberUtils.hideBit(baseInfo.getPassport(), NumberHideConstant.PASSPORT_HIDE);
        } else {
            this.idNumber = baseInfo.getIdNumber();
            this.phoneNumbers = baseInfo.buildPhone();
            this.plateNumbers = baseInfo.buildPlate();
            this.bankAccounts = baseInfo.buildBankAccount();
            this.passport = baseInfo.getPassport();
        }
        this.educationExperiences = baseInfo.buildEducationExperience();
        this.workExperiences = baseInfo.buildWorkExperience();
        this.political = baseInfo.getPolitical();
        this.familySituation = baseInfo.getFamilySituation();
        this.personalSituation = baseInfo.getPersonalSituation();
        this.archivesJudgment = baseInfo.getArchivesJudgment();
        this.note = baseInfo.getNote();
        this.createTime = baseInfo.getCreateTime();
        this.updateTime = baseInfo.getUpdateTime();
        this.creator = baseInfo.getCreatorName();
    }


    public void companyInfo(ArchivesCompanyInfo companyInfo) {
        this.companyInfo = companyInfo == null ? null : new ArchivesVO.CompanyInfo(companyInfo);
    }

    public void socialInfo(ArchivesSocialInfo socialInfo) {
        this.socialInfo = socialInfo == null ? null : new SocialInfo(socialInfo);
    }

    @Data
    @NoArgsConstructor
    public static class SocialInfo {

        /**
         * 社交媒体
         */

        private List<Info> socialInfos;

        /**
         * 电子邮箱
         */
        private List<ArchivesVO.SocialInfo.Email> emailInfo;

        /**
         * 钱包地址
         */
        private List<ArchivesVO.SocialInfo.Wallet> walletInfo;

        /**
         * 数据泄露
         */
        private String dataLeakage;

        public SocialInfo(ArchivesSocialInfo socialInfo) {
            this.socialInfos = socialInfo.buildSocialDetailInfo();
            this.emailInfo = socialInfo.buildSocialEmail();
            this.walletInfo = socialInfo.buildSocialWallet();
            this.dataLeakage = socialInfo.getDataLeakage();
        }

        @Data
        public static class Info {
            private String socialPlatform;
            List<ArchivesVO.SocialInfo.SocialInfoInner> socialInfoInners;
        }
    }


}
